package com.hrms.hrms_recruitment.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.api.ApiController;
import com.baomidou.mybatisplus.extension.api.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hrms.common.utils.RequestUtil;
import com.hrms.common.vo.PageVo;
import com.hrms.common.vo.ResultMessage;
import com.hrms.hrms_recruitment.entity.Recruit;
import com.hrms.hrms_recruitment.service.RecruitService;
import com.hrms.hrms_recruitment.vo.RecruitVO;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.Serializable;
import java.util.List;
import java.util.Map;

/**
 * (Recruit)表控制层
 *
 * @author makejava
 * @since 2025-01-14 16:11:57
 */
@RestController
@RequestMapping("recruit")
public class RecruitController extends ApiController {
    /**
     * 服务对象
     */
    @Resource
    private RecruitService recruitService;

    /**
     * 分页查询所有数据
     *
     * @param pageVo 分页对象
     * @param request 查询
     * @return 所有数据
     */
    @GetMapping
    public ResultMessage selectAll(PageVo pageVo, HttpServletRequest request) {
        Page<RecruitVO> page = new Page<>(pageVo.getCurrent(), pageVo.getSize());
        RequestUtil requestUtil = new RequestUtil();
        Map<String, String> map = requestUtil.getParameterMap(request);
        Page<RecruitVO> recruitPage = this.recruitService.pageInfo(page, map);
        return new ResultMessage(ResultMessage.Success,"",recruitPage);
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("/one")
    public ResultMessage selectOne(@RequestParam Long id) {
        RecruitVO recruitVO = this.recruitService.getDetailsById(id);
        return new ResultMessage(ResultMessage.Success,"",recruitVO);
    }

    /**
     * 新增招聘需求数据，开启流程审批
     *
     * @param recruitvo 实体对象
     * @return 新增结果
     */
    @PostMapping
    public ResultMessage insert(@RequestBody RecruitVO recruitvo) {
        this.recruitService.saveAndStartFlow(recruitvo);
        return new ResultMessage(ResultMessage.Success,"");
    }

    /**
     * 招聘审批结束修改数据
     *
     * @param
     * @return 修改结果
     */
    @PutMapping
    public ResultMessage update(@RequestParam String id) {
        this.recruitService.updateByDetails(id);
        return new ResultMessage(ResultMessage.Success,"");
    }

    /**
     * 面试审批修改数据
     *
     * @param
     * @return 修改结果
     */
    @PutMapping("/updateInterview")
    public ResultMessage updateInterview(@RequestParam String id) {
        this.recruitService.updateInterViewByDetails(Long.valueOf(id));
        return new ResultMessage(ResultMessage.Success,"");
    }

    /**
     * 删除数据
     *
     * @param idList 主键结合
     * @return 删除结果
     */
    @DeleteMapping
    public R delete(@RequestParam("idList") List<Long> idList) {
        return success(this.recruitService.removeByIds(idList));
    }
}

